﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WaveringLand_Launcher.Helper.Net;
using WaveringLand_Launcher.Model;

namespace WaveringLand_Launcher.Helper
{
    public class ResHelper
    {

        private static string[] MustCategories = { "ServersDat", "Mods.Must"};

        private static bool CheckIsMust(WllFile file)
        {
            return MustCategories.ToList().Contains(file.Category);
        }
        /// <summary>
        /// 获取多余的Mods,通过路径直接判断
        /// </summary>
        /// <returns></returns>
        public async static Task<List<string>> GetExcessMods()
        {
            List<String> strs = new List<string>();
            var dir =  Directory.GetCurrentDirectory() + "\\.minecraft\\mods";
            var list = Directory.GetFiles(dir);
            var latest =await WlTaskHelper.GetLatestIndexAsync();
            
            foreach (var item in list)
            {
                if (!latest.Exists(x => Path.GetFullPath(x.Path) == item))
                {
                    strs.Add(item);
                }
            }
            return strs;
        }

        public async static Task<List<WllFile>> GetLackMustFiles()
        {
            var list = new List<WllFile>();

            var latest = await WlTaskHelper.GetLatestIndexAsync();
            foreach (var item in latest.Where(x => CheckIsMust(x)))
            {
                if (File.Exists(Path.GetFullPath(item.Path)) is false)
                {
                    list.Add(item);
                }
            }

            return list;
            

        }
    }
}
